<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: Capture Sinusoidal pattern tutorial</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../d3/d81/tutorial_contrib_root.html">Tutorials for contrib modules</a></li><li class="navelem"><a class="el" href="../../d3/d81/tutorial_structured_light.html">Structured Light tutorials</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Capture Sinusoidal pattern tutorial </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h2>Goal </h2>
<p>In this tutorial, you will learn how to use the sinusoidal pattern class to:</p>
<ul>
<li>Generate sinusoidal patterns.</li>
<li>Project the generated patterns.</li>
<li>Capture the projected patterns.</li>
<li>Compute a wrapped phase map from these patterns using three different algorithms (Fourier Transform Profilometry, Phase Shifting Profilometry, Fourier-assisted Phase Shifting Profilometry)</li>
<li>Unwrap the previous phase map.</li>
</ul>
<h2>Code </h2>
<div class="fragment"><div class="line"><span class="comment">/*M///////////////////////////////////////////////////////////////////////////////////////</span></div><div class="line"><span class="comment"> //</span></div><div class="line"><span class="comment"> //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.</span></div><div class="line"><span class="comment"> //</span></div><div class="line"><span class="comment"> //  By downloading, copying, installing or using the software you agree to this license.</span></div><div class="line"><span class="comment"> //  If you do not agree to this license, do not download, install,</span></div><div class="line"><span class="comment"> //  copy or use the software.</span></div><div class="line"><span class="comment"> //</span></div><div class="line"><span class="comment"> //</span></div><div class="line"><span class="comment"> //                           License Agreement</span></div><div class="line"><span class="comment"> //                For Open Source Computer Vision Library</span></div><div class="line"><span class="comment"> //</span></div><div class="line"><span class="comment"> // Copyright (C) 2015, OpenCV Foundation, all rights reserved.</span></div><div class="line"><span class="comment"> // Third party copyrights are property of their respective owners.</span></div><div class="line"><span class="comment"> //</span></div><div class="line"><span class="comment"> // Redistribution and use in source and binary forms, with or without modification,</span></div><div class="line"><span class="comment"> // are permitted provided that the following conditions are met:</span></div><div class="line"><span class="comment"> //</span></div><div class="line"><span class="comment"> //   * Redistribution&#39;s of source code must retain the above copyright notice,</span></div><div class="line"><span class="comment"> //     this list of conditions and the following disclaimer.</span></div><div class="line"><span class="comment"> //</span></div><div class="line"><span class="comment"> //   * Redistribution&#39;s in binary form must reproduce the above copyright notice,</span></div><div class="line"><span class="comment"> //     this list of conditions and the following disclaimer in the documentation</span></div><div class="line"><span class="comment"> //     and/or other materials provided with the distribution.</span></div><div class="line"><span class="comment"> //</span></div><div class="line"><span class="comment"> //   * The name of the copyright holders may not be used to endorse or promote products</span></div><div class="line"><span class="comment"> //     derived from this software without specific prior written permission.</span></div><div class="line"><span class="comment"> //</span></div><div class="line"><span class="comment"> // This software is provided by the copyright holders and contributors &quot;as is&quot; and</span></div><div class="line"><span class="comment"> // any express or implied warranties, including, but not limited to, the implied</span></div><div class="line"><span class="comment"> // warranties of merchantability and fitness for a particular purpose are disclaimed.</span></div><div class="line"><span class="comment"> // In no event shall the Intel Corporation or contributors be liable for any direct,</span></div><div class="line"><span class="comment"> // indirect, incidental, special, exemplary, or consequential damages</span></div><div class="line"><span class="comment"> // (including, but not limited to, procurement of substitute goods or services;</span></div><div class="line"><span class="comment"> // loss of use, data, or profits; or business interruption) however caused</span></div><div class="line"><span class="comment"> // and on any theory of liability, whether in contract, strict liability,</span></div><div class="line"><span class="comment"> // or tort (including negligence or otherwise) arising in any way out of</span></div><div class="line"><span class="comment"> // the use of this software, even if advised of the possibility of such damage.</span></div><div class="line"><span class="comment"> //</span></div><div class="line"><span class="comment"> //M*/</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d4/dd5/highgui_8hpp.html">opencv2/highgui.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;vector&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;fstream&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d0/d9c/core_2include_2opencv2_2core_8hpp.html">opencv2/core.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d1/d4e/utility_8hpp.html">opencv2/core/utility.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d1/d4f/imgproc_2include_2opencv2_2imgproc_8hpp.html">opencv2/imgproc.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d2/d28/calib3d_8hpp.html">opencv2/calib3d.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d3/d23/structured__light_8hpp.html">opencv2/structured_light.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../dd/dee/phase__unwrapping_8hpp.html">opencv2/phase_unwrapping.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d2/d75/namespacecv.html">cv</a>;</div><div class="line"><span class="keyword">using namespace </span>std;</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* keys =</div><div class="line">{</div><div class="line">    <span class="stringliteral">&quot;{@width | | Projector width}&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{@height | | Projector height}&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{@periods | | Number of periods}&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{@setMarkers | | Patterns with or without markers}&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{@horizontal | | Patterns are horizontal}&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{@methodId | | Method to be used}&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{@outputPatternPath | | Path to save patterns}&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{@outputWrappedPhasePath | | Path to save wrapped phase map}&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{@outputUnwrappedPhasePath | | Path to save unwrapped phase map}&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{@outputCapturePath | | Path to save the captures}&quot;</span></div><div class="line">    <span class="stringliteral">&quot;{@reliabilitiesPath | | Path to save reliabilities}&quot;</span></div><div class="line">};</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> help()</div><div class="line">{</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;\nThis example generates sinusoidal patterns&quot;</span> &lt;&lt; endl;</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;To call: ./example_structured_light_createsinuspattern &lt;width&gt; &lt;height&gt;&quot;</span></div><div class="line">            <span class="stringliteral">&quot; &lt;number_of_period&gt; &lt;set_marker&gt;(bool) &lt;horizontal_patterns&gt;(bool) &lt;method_id&gt;&quot;</span></div><div class="line">            <span class="stringliteral">&quot; &lt;output_captures_path&gt; &lt;output_pattern_path&gt;(optional) &lt;output_wrapped_phase_path&gt; (optional)&quot;</span></div><div class="line">            <span class="stringliteral">&quot; &lt;output_unwrapped_phase_path&gt;&quot;</span> &lt;&lt; endl;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div><div class="line">{</div><div class="line">    <span class="keywordflow">if</span>( argc &lt; 2 )</div><div class="line">    {</div><div class="line">        help();</div><div class="line">        <span class="keywordflow">return</span> -1;</div><div class="line">    }</div><div class="line">    <a class="code" href="../../df/d21/structcv_1_1structured__light_1_1SinusoidalPattern_1_1Params.html">structured_light::SinusoidalPattern::Params</a> <a class="code" href="../../d1/dae/namespacecv_1_1gapi_1_1ie.html#a3ab1729bcaf2d08e30dd2bc645410908">params</a>;</div><div class="line">    <a class="code" href="../../d6/d86/structcv_1_1phase__unwrapping_1_1HistogramPhaseUnwrapping_1_1Params.html">phase_unwrapping::HistogramPhaseUnwrapping::Params</a> paramsUnwrapping;</div><div class="line"></div><div class="line">    <span class="comment">// Retrieve parameters written in the command line</span></div><div class="line">    <a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html">CommandLineParser</a> parser(argc, argv, keys);</div><div class="line">    params.<a class="code" href="../../df/d21/structcv_1_1structured__light_1_1SinusoidalPattern_1_1Params.html#a5e78febfc43f763b3902cd6360d5e1a2">width</a> = parser.get&lt;<span class="keywordtype">int</span>&gt;(0);</div><div class="line">    params.<a class="code" href="../../df/d21/structcv_1_1structured__light_1_1SinusoidalPattern_1_1Params.html#a1928f2537c463e85857acbd1fd620b29">height</a> = parser.get&lt;<span class="keywordtype">int</span>&gt;(1);</div><div class="line">    params.<a class="code" href="../../df/d21/structcv_1_1structured__light_1_1SinusoidalPattern_1_1Params.html#a6de65e87b137bcbef73eaf5c255f1376">nbrOfPeriods</a> = parser.get&lt;<span class="keywordtype">int</span>&gt;(2);</div><div class="line">    params.<a class="code" href="../../df/d21/structcv_1_1structured__light_1_1SinusoidalPattern_1_1Params.html#a1b8a00a40198b20bd935d499257267c6">setMarkers</a> = parser.get&lt;<span class="keywordtype">bool</span>&gt;(3);</div><div class="line">    params.<a class="code" href="../../df/d21/structcv_1_1structured__light_1_1SinusoidalPattern_1_1Params.html#ae7297d16cebc75ef79f227730c651cf1">horizontal</a> = parser.get&lt;<span class="keywordtype">bool</span>&gt;(4);</div><div class="line">    params.<a class="code" href="../../df/d21/structcv_1_1structured__light_1_1SinusoidalPattern_1_1Params.html#afbbc6da65b06b05e696bfa95b3326f52">methodId</a> = parser.get&lt;<span class="keywordtype">int</span>&gt;(5);</div><div class="line">    <a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> outputCapturePath = parser.get&lt;<a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a>&gt;(6);</div><div class="line"></div><div class="line">    params.<a class="code" href="../../df/d21/structcv_1_1structured__light_1_1SinusoidalPattern_1_1Params.html#a59e0895b9e37f8af2f9ff659697ae5d0">shiftValue</a> = <span class="keyword">static_cast&lt;</span><span class="keywordtype">float</span><span class="keyword">&gt;</span>(2 * CV_PI / 3);</div><div class="line">    params.<a class="code" href="../../df/d21/structcv_1_1structured__light_1_1SinusoidalPattern_1_1Params.html#a16f802cb311a1bd401740755eb12fffd">nbrOfPixelsBetweenMarkers</a> = 70;</div><div class="line">    <a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> outputPatternPath = parser.get&lt;<a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a>&gt;(7);</div><div class="line">    <a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> outputWrappedPhasePath = parser.get&lt;<a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a>&gt;(8);</div><div class="line">    <a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> outputUnwrappedPhasePath = parser.get&lt;<a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a>&gt;(9);</div><div class="line">    <a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> reliabilitiesPath = parser.get&lt;<a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a>&gt;(10);</div><div class="line"></div><div class="line">    <a class="code" href="../../dc/d84/group__core__basic.html#ga6395ca871a678020c4a31fadf7e8cc63">Ptr&lt;structured_light::SinusoidalPattern&gt;</a> sinus =</div><div class="line">            <a class="code" href="../../d6/d96/classcv_1_1structured__light_1_1SinusoidalPattern.html#a97045af313f2fa0fa68b12734cf48320">structured_light::SinusoidalPattern::create</a>(makePtr&lt;structured_light::SinusoidalPattern::Params&gt;(params));</div><div class="line">    <a class="code" href="../../dc/d84/group__core__basic.html#ga6395ca871a678020c4a31fadf7e8cc63">Ptr&lt;phase_unwrapping::HistogramPhaseUnwrapping&gt;</a> phaseUnwrapping;</div><div class="line"></div><div class="line">    vector&lt;Mat&gt; patterns;</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> shadowMask;</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> unwrappedPhaseMap, unwrappedPhaseMap8;</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> wrappedPhaseMap, wrappedPhaseMap8;</div><div class="line">    <span class="comment">//Generate sinusoidal patterns</span></div><div class="line">    sinus-&gt;generate(patterns);</div><div class="line"></div><div class="line"></div><div class="line">    <a class="code" href="../../d8/dfe/classcv_1_1VideoCapture.html">VideoCapture</a> cap(<a class="code" href="../../d4/d15/group__videoio__flags__base.html#gga023786be1ee68a9105bf2e48c700294daea3f59a31f396298b5b3531c23391e49">CAP_PVAPI</a>);</div><div class="line">    <span class="keywordflow">if</span>( !cap.isOpened() )</div><div class="line">    {</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Camera could not be opened&quot;</span> &lt;&lt; endl;</div><div class="line">        <span class="keywordflow">return</span> -1;</div><div class="line">    }</div><div class="line">    cap.set(<a class="code" href="../../dc/dfc/group__videoio__flags__others.html#ggaf63d4c617c61e03ab502b3c836966150af398d565fa74a15b5336cd7d7b4875c1">CAP_PROP_PVAPI_PIXELFORMAT</a>, <a class="code" href="../../dc/dfc/group__videoio__flags__others.html#gga89a5ea2c97ef26165c47e792380b96bca7910aa88e73d326883f0742f760ecae1">CAP_PVAPI_PIXELFORMAT_MONO8</a>);</div><div class="line"></div><div class="line">    <a class="code" href="../../d7/dfc/group__highgui.html#ga5afdf8410934fd099df85c75b2e0888b">namedWindow</a>(<span class="stringliteral">&quot;pattern&quot;</span>, <a class="code" href="../../d0/d90/group__highgui__window__flags.html#ggabf7d2c5625bc59ac130287f925557ac3a29e45c5af696f73ce5e153601e5ca0f1">WINDOW_NORMAL</a>);</div><div class="line">    <a class="code" href="../../d7/dfc/group__highgui.html#ga66e4a6db4d4e06148bcdfe0d70a5df27">setWindowProperty</a>(<span class="stringliteral">&quot;pattern&quot;</span>, <a class="code" href="../../d0/d90/group__highgui__window__flags.html#ggaeedf4023e777f896ba6b9ffb156f57b8a3b6a89b0daf2149dab93f9c6ab99fcc8">WND_PROP_FULLSCREEN</a>, <a class="code" href="../../d0/d90/group__highgui__window__flags.html#ggabf7d2c5625bc59ac130287f925557ac3a78bc64121f612562bbb2fa23d316e84e">WINDOW_FULLSCREEN</a>);</div><div class="line">    <a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a>(<span class="stringliteral">&quot;pattern&quot;</span>, patterns[0]);</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;Press any key when ready&quot;</span> &lt;&lt; endl;</div><div class="line">    <a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a>(0);</div><div class="line"></div><div class="line">    <span class="keywordtype">int</span> nbrOfImages = 30;</div><div class="line">    <span class="keywordtype">int</span> count = 0;</div><div class="line"></div><div class="line">    vector&lt;Mat&gt; img(nbrOfImages);</div><div class="line">    <a class="code" href="../../d6/d50/classcv_1_1Size__.html">Size</a> camSize(-1, -1);</div><div class="line"></div><div class="line">    <span class="keywordflow">while</span>( count &lt; nbrOfImages )</div><div class="line">    {</div><div class="line">        <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i &lt; (int)patterns.size(); ++i )</div><div class="line">        {</div><div class="line">            <a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a>(<span class="stringliteral">&quot;pattern&quot;</span>, patterns[i]);</div><div class="line">            <a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a>(300);</div><div class="line">            cap &gt;&gt; img[count];</div><div class="line">            count += 1;</div><div class="line">        }</div><div class="line">    }</div><div class="line"></div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;press enter when ready&quot;</span> &lt;&lt; endl;</div><div class="line">    <span class="keywordtype">bool</span> loop = <span class="keyword">true</span>;</div><div class="line">    <span class="keywordflow">while</span> ( loop )</div><div class="line">    {</div><div class="line">        <span class="keywordtype">char</span> c = (char) <a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a>(0);</div><div class="line">        <span class="keywordflow">if</span>( c == 10 )</div><div class="line">        {</div><div class="line">            loop = <span class="keyword">false</span>;</div><div class="line">        }</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordflow">switch</span>(params.<a class="code" href="../../df/d21/structcv_1_1structured__light_1_1SinusoidalPattern_1_1Params.html#afbbc6da65b06b05e696bfa95b3326f52">methodId</a>)</div><div class="line">    {</div><div class="line">        <span class="keywordflow">case</span> <a class="code" href="../../d1/d90/group__structured__light.html#gga8c656fa76189bd6dc1b2a444f680b60aa4652f36554cab9ec596798cdb98aa1c7">structured_light::FTP</a>:</div><div class="line">            <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i = 0; i &lt; nbrOfImages; ++i )</div><div class="line">            {</div><div class="line">                <span class="comment">/*We need three images to compute the shadow mask, as described in the reference paper</span></div><div class="line"><span class="comment">                 * even if the phase map is computed from one pattern only</span></div><div class="line"><span class="comment">                */</span></div><div class="line">                vector&lt;Mat&gt; captures;</div><div class="line">                <span class="keywordflow">if</span>( i == nbrOfImages - 2 )</div><div class="line">                {</div><div class="line">                    captures.push_back(img[i]);</div><div class="line">                    captures.push_back(img[i-1]);</div><div class="line">                    captures.push_back(img[i+1]);</div><div class="line">                }</div><div class="line">                <span class="keywordflow">else</span> <span class="keywordflow">if</span>( i == nbrOfImages - 1 )</div><div class="line">                {</div><div class="line">                    captures.push_back(img[i]);</div><div class="line">                    captures.push_back(img[i-1]);</div><div class="line">                    captures.push_back(img[i-2]);</div><div class="line">                }</div><div class="line">                <span class="keywordflow">else</span></div><div class="line">                {</div><div class="line">                    captures.push_back(img[i]);</div><div class="line">                    captures.push_back(img[i+1]);</div><div class="line">                    captures.push_back(img[i+2]);</div><div class="line">                }</div><div class="line">                sinus-&gt;computePhaseMap(captures, wrappedPhaseMap, shadowMask);</div><div class="line">                <span class="keywordflow">if</span>( camSize.height == -1 )</div><div class="line">                {</div><div class="line">                    camSize.height = img[i].rows;</div><div class="line">                    camSize.width = img[i].cols;</div><div class="line">                    paramsUnwrapping.<a class="code" href="../../d6/d86/structcv_1_1phase__unwrapping_1_1HistogramPhaseUnwrapping_1_1Params.html#a6cafef26e8a22e1b738baa21718da4b5">height</a> = camSize.height;</div><div class="line">                    paramsUnwrapping.<a class="code" href="../../d6/d86/structcv_1_1phase__unwrapping_1_1HistogramPhaseUnwrapping_1_1Params.html#a4a47c8f96db147266a877be2697046c2">width</a> = camSize.width;</div><div class="line">                    phaseUnwrapping =</div><div class="line">                    <a class="code" href="../../d5/d7d/classcv_1_1phase__unwrapping_1_1HistogramPhaseUnwrapping.html#a36b20dc34658c5cff6790775f949187f">phase_unwrapping::HistogramPhaseUnwrapping::create</a>(paramsUnwrapping);</div><div class="line">                }</div><div class="line">                sinus-&gt;unwrapPhaseMap(wrappedPhaseMap, unwrappedPhaseMap, camSize, shadowMask);</div><div class="line"></div><div class="line">                phaseUnwrapping-&gt;unwrapPhaseMap(wrappedPhaseMap, unwrappedPhaseMap, shadowMask);</div><div class="line">                <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> reliabilities, reliabilities8;</div><div class="line">                phaseUnwrapping-&gt;getInverseReliabilityMap(reliabilities);</div><div class="line">                reliabilities.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#adf88c60c5b4980e05bb556080916978b">convertTo</a>(reliabilities8, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga32b18d904ee2b1731a9416a8eef67d06">CV_8U</a>, 255,128);</div><div class="line"></div><div class="line">                ostringstream tt;</div><div class="line">                tt &lt;&lt; i;</div><div class="line">                <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(reliabilitiesPath + tt.str() + <span class="stringliteral">&quot;.png&quot;</span>, reliabilities8);</div><div class="line"></div><div class="line">                unwrappedPhaseMap.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#adf88c60c5b4980e05bb556080916978b">convertTo</a>(unwrappedPhaseMap8, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga32b18d904ee2b1731a9416a8eef67d06">CV_8U</a>, 1, 128);</div><div class="line">                wrappedPhaseMap.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#adf88c60c5b4980e05bb556080916978b">convertTo</a>(wrappedPhaseMap8, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga32b18d904ee2b1731a9416a8eef67d06">CV_8U</a>, 255, 128);</div><div class="line"></div><div class="line">                <span class="keywordflow">if</span>( !outputUnwrappedPhasePath.empty() )</div><div class="line">                {</div><div class="line">                    ostringstream name;</div><div class="line">                    name &lt;&lt; i;</div><div class="line">                    <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputUnwrappedPhasePath + <span class="stringliteral">&quot;_FTP_&quot;</span> + name.str() + <span class="stringliteral">&quot;.png&quot;</span>, unwrappedPhaseMap8);</div><div class="line">                }</div><div class="line"></div><div class="line">                <span class="keywordflow">if</span>( !outputWrappedPhasePath.empty() )</div><div class="line">                {</div><div class="line">                    ostringstream name;</div><div class="line">                    name &lt;&lt; i;</div><div class="line">                    <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputWrappedPhasePath + <span class="stringliteral">&quot;_FTP_&quot;</span> + name.str() + <span class="stringliteral">&quot;.png&quot;</span>, wrappedPhaseMap8);</div><div class="line">                }</div><div class="line">            }</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        <span class="keywordflow">case</span> <a class="code" href="../../d1/d90/group__structured__light.html#gga8c656fa76189bd6dc1b2a444f680b60aa1642d3774551cc6161f49359cc4dd3af">structured_light::PSP</a>:</div><div class="line">        <span class="keywordflow">case</span> <a class="code" href="../../d1/d90/group__structured__light.html#gga8c656fa76189bd6dc1b2a444f680b60aa7f8cbabe23690dec5c877978aa57be7c">structured_light::FAPS</a>:</div><div class="line">            <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i = 0; i &lt; nbrOfImages - 2; ++i )</div><div class="line">            {</div><div class="line">                vector&lt;Mat&gt; captures;</div><div class="line">                captures.push_back(img[i]);</div><div class="line">                captures.push_back(img[i+1]);</div><div class="line">                captures.push_back(img[i+2]);</div><div class="line"></div><div class="line">                sinus-&gt;computePhaseMap(captures, wrappedPhaseMap, shadowMask);</div><div class="line"></div><div class="line">                <span class="keywordflow">if</span>( camSize.height == -1 )</div><div class="line">                {</div><div class="line">                    camSize.height = img[i].rows;</div><div class="line">                    camSize.width = img[i].cols;</div><div class="line">                    paramsUnwrapping.<a class="code" href="../../d6/d86/structcv_1_1phase__unwrapping_1_1HistogramPhaseUnwrapping_1_1Params.html#a6cafef26e8a22e1b738baa21718da4b5">height</a> = camSize.height;</div><div class="line">                    paramsUnwrapping.<a class="code" href="../../d6/d86/structcv_1_1phase__unwrapping_1_1HistogramPhaseUnwrapping_1_1Params.html#a4a47c8f96db147266a877be2697046c2">width</a> = camSize.width;</div><div class="line">                    phaseUnwrapping =</div><div class="line">                    <a class="code" href="../../d5/d7d/classcv_1_1phase__unwrapping_1_1HistogramPhaseUnwrapping.html#a36b20dc34658c5cff6790775f949187f">phase_unwrapping::HistogramPhaseUnwrapping::create</a>(paramsUnwrapping);</div><div class="line">                }</div><div class="line">                sinus-&gt;unwrapPhaseMap(wrappedPhaseMap, unwrappedPhaseMap, camSize, shadowMask);</div><div class="line">                unwrappedPhaseMap.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#adf88c60c5b4980e05bb556080916978b">convertTo</a>(unwrappedPhaseMap8, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga32b18d904ee2b1731a9416a8eef67d06">CV_8U</a>, 1, 128);</div><div class="line">                wrappedPhaseMap.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#adf88c60c5b4980e05bb556080916978b">convertTo</a>(wrappedPhaseMap8, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga32b18d904ee2b1731a9416a8eef67d06">CV_8U</a>, 255, 128);</div><div class="line"></div><div class="line">                phaseUnwrapping-&gt;unwrapPhaseMap(wrappedPhaseMap, unwrappedPhaseMap, shadowMask);</div><div class="line">                <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> reliabilities, reliabilities8;</div><div class="line">                phaseUnwrapping-&gt;getInverseReliabilityMap(reliabilities);</div><div class="line">                reliabilities.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#adf88c60c5b4980e05bb556080916978b">convertTo</a>(reliabilities8, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga32b18d904ee2b1731a9416a8eef67d06">CV_8U</a>, 255,128);</div><div class="line"></div><div class="line">                ostringstream tt;</div><div class="line">                tt &lt;&lt; i;</div><div class="line">                <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(reliabilitiesPath + tt.str() + <span class="stringliteral">&quot;.png&quot;</span>, reliabilities8);</div><div class="line"></div><div class="line">                <span class="keywordflow">if</span>( !outputUnwrappedPhasePath.empty() )</div><div class="line">                {</div><div class="line">                    ostringstream name;</div><div class="line">                    name &lt;&lt; i;</div><div class="line">                    <span class="keywordflow">if</span>( params.<a class="code" href="../../df/d21/structcv_1_1structured__light_1_1SinusoidalPattern_1_1Params.html#afbbc6da65b06b05e696bfa95b3326f52">methodId</a> == <a class="code" href="../../d1/d90/group__structured__light.html#gga8c656fa76189bd6dc1b2a444f680b60aa1642d3774551cc6161f49359cc4dd3af">structured_light::PSP</a> )</div><div class="line">                        <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputUnwrappedPhasePath + <span class="stringliteral">&quot;_PSP_&quot;</span> + name.str() + <span class="stringliteral">&quot;.png&quot;</span>, unwrappedPhaseMap8);</div><div class="line">                    <span class="keywordflow">else</span></div><div class="line">                        <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputUnwrappedPhasePath + <span class="stringliteral">&quot;_FAPS_&quot;</span> + name.str() + <span class="stringliteral">&quot;.png&quot;</span>, unwrappedPhaseMap8);</div><div class="line">                }</div><div class="line"></div><div class="line">                <span class="keywordflow">if</span>( !outputWrappedPhasePath.empty() )</div><div class="line">                {</div><div class="line">                    ostringstream name;</div><div class="line">                    name &lt;&lt; i;</div><div class="line">                    <span class="keywordflow">if</span>( params.<a class="code" href="../../df/d21/structcv_1_1structured__light_1_1SinusoidalPattern_1_1Params.html#afbbc6da65b06b05e696bfa95b3326f52">methodId</a> == <a class="code" href="../../d1/d90/group__structured__light.html#gga8c656fa76189bd6dc1b2a444f680b60aa1642d3774551cc6161f49359cc4dd3af">structured_light::PSP</a> )</div><div class="line">                        <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputWrappedPhasePath + <span class="stringliteral">&quot;_PSP_&quot;</span> + name.str() + <span class="stringliteral">&quot;.png&quot;</span>, wrappedPhaseMap8);</div><div class="line">                    <span class="keywordflow">else</span></div><div class="line">                        <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputWrappedPhasePath + <span class="stringliteral">&quot;_FAPS_&quot;</span> + name.str() + <span class="stringliteral">&quot;.png&quot;</span>, wrappedPhaseMap8);</div><div class="line">                }</div><div class="line"></div><div class="line">                <span class="keywordflow">if</span>( !outputCapturePath.empty() )</div><div class="line">                {</div><div class="line">                    ostringstream name;</div><div class="line">                    name &lt;&lt; i;</div><div class="line">                    <span class="keywordflow">if</span>( params.<a class="code" href="../../df/d21/structcv_1_1structured__light_1_1SinusoidalPattern_1_1Params.html#afbbc6da65b06b05e696bfa95b3326f52">methodId</a> == <a class="code" href="../../d1/d90/group__structured__light.html#gga8c656fa76189bd6dc1b2a444f680b60aa1642d3774551cc6161f49359cc4dd3af">structured_light::PSP</a> )</div><div class="line">                        <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputCapturePath + <span class="stringliteral">&quot;_PSP_&quot;</span> + name.str() + <span class="stringliteral">&quot;.png&quot;</span>, img[i]);</div><div class="line">                    <span class="keywordflow">else</span></div><div class="line">                        <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputCapturePath + <span class="stringliteral">&quot;_FAPS_&quot;</span> + name.str() + <span class="stringliteral">&quot;.png&quot;</span>, img[i]);</div><div class="line">                    <span class="keywordflow">if</span>( i == nbrOfImages - 3 )</div><div class="line">                    {</div><div class="line">                        <span class="keywordflow">if</span>( params.<a class="code" href="../../df/d21/structcv_1_1structured__light_1_1SinusoidalPattern_1_1Params.html#afbbc6da65b06b05e696bfa95b3326f52">methodId</a> == <a class="code" href="../../d1/d90/group__structured__light.html#gga8c656fa76189bd6dc1b2a444f680b60aa1642d3774551cc6161f49359cc4dd3af">structured_light::PSP</a> )</div><div class="line">                        {</div><div class="line">                            ostringstream nameBis;</div><div class="line">                            nameBis &lt;&lt; i+1;</div><div class="line">                            ostringstream nameTer;</div><div class="line">                            nameTer &lt;&lt; i+2;</div><div class="line">                            <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputCapturePath + <span class="stringliteral">&quot;_PSP_&quot;</span> + nameBis.str() + <span class="stringliteral">&quot;.png&quot;</span>, img[i+1]);</div><div class="line">                            <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputCapturePath + <span class="stringliteral">&quot;_PSP_&quot;</span> + nameTer.str() + <span class="stringliteral">&quot;.png&quot;</span>, img[i+2]);</div><div class="line">                        }</div><div class="line">                        <span class="keywordflow">else</span></div><div class="line">                        {</div><div class="line">                            ostringstream nameBis;</div><div class="line">                            nameBis &lt;&lt; i+1;</div><div class="line">                            ostringstream nameTer;</div><div class="line">                            nameTer &lt;&lt; i+2;</div><div class="line">                            <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputCapturePath + <span class="stringliteral">&quot;_FAPS_&quot;</span> + nameBis.str() + <span class="stringliteral">&quot;.png&quot;</span>, img[i+1]);</div><div class="line">                            <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputCapturePath + <span class="stringliteral">&quot;_FAPS_&quot;</span> + nameTer.str() + <span class="stringliteral">&quot;.png&quot;</span>, img[i+2]);</div><div class="line">                        }</div><div class="line">                    }</div><div class="line">                }</div><div class="line">            }</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        <span class="keywordflow">default</span>:</div><div class="line">            cout &lt;&lt; <span class="stringliteral">&quot;error&quot;</span> &lt;&lt; endl;</div><div class="line">    }</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;done&quot;</span> &lt;&lt; endl;</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span>( !outputPatternPath.empty() )</div><div class="line">    {</div><div class="line">        <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i = 0; i &lt; 3; ++ i )</div><div class="line">        {</div><div class="line">            ostringstream name;</div><div class="line">            name &lt;&lt; i + 1;</div><div class="line">            <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputPatternPath + name.str() + <span class="stringliteral">&quot;.png&quot;</span>, patterns[i]);</div><div class="line">        }</div><div class="line">    }</div><div class="line"></div><div class="line">    loop = <span class="keyword">true</span>;</div><div class="line">    <span class="keywordflow">while</span>( loop )</div><div class="line">    {</div><div class="line">        <span class="keywordtype">char</span> key = (char) <a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a>(0);</div><div class="line">        <span class="keywordflow">if</span>( key == 27 )</div><div class="line">        {</div><div class="line">            loop = <span class="keyword">false</span>;</div><div class="line">        }</div><div class="line">    }</div><div class="line">    <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --><h2>Expalantion </h2>
<p>First, the sinusoidal patterns must be generated. <em>SinusoidalPattern</em> class parameters have to be set by the user:</p>
<ul>
<li>projector width and height</li>
<li>number of periods in the patterns</li>
<li>set cross markers in the patterns (used to convert relative phase map to absolute phase map)</li>
<li>patterns direction (horizontal or vertical)</li>
<li>phase shift value (usually set to 2pi/3 to enable a cyclical system)</li>
<li>number of pixels between two consecutive markers on the same row/column</li>
<li>id of the method used to compute the phase map (FTP = 0, PSP = 1, FAPS = 2)</li>
</ul>
<p>The user can also choose to save the patterns and the phase map.</p>
<div class="fragment"><div class="line"><a class="code" href="../../d4/d41/namespacecv_1_1dynafu.html#afe352b7045bf5f1496c2d8dd2a09a764">structured_light::SinusoidalPattern::Params</a> <a class="code" href="../../d1/dae/namespacecv_1_1gapi_1_1ie.html#a3ab1729bcaf2d08e30dd2bc645410908">params</a>;</div><div class="line">params.width = parser.get&lt;<span class="keywordtype">int</span>&gt;(0);</div><div class="line">params.height = parser.get&lt;<span class="keywordtype">int</span>&gt;(1);</div><div class="line">params.nbrOfPeriods = parser.get&lt;<span class="keywordtype">int</span>&gt;(2);</div><div class="line">params.setMarkers = parser.get&lt;<span class="keywordtype">bool</span>&gt;(3);</div><div class="line">params.horizontal = parser.get&lt;<span class="keywordtype">bool</span>&gt;(4);</div><div class="line">params.methodId = parser.get&lt;<span class="keywordtype">int</span>&gt;(5);</div><div class="line">params.shiftValue = <span class="keyword">static_cast&lt;</span><span class="keywordtype">float</span><span class="keyword">&gt;</span>(2 * CV_PI / 3);</div><div class="line">params.nbrOfPixelsBetweenMarkers = 70;</div><div class="line"><a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> outputPatternPath = parser.get&lt;<a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a>&gt;(6);</div><div class="line"><a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> outputWrappedPhasePath = parser.get&lt;<a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a>&gt;(7);</div><div class="line"><a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> outputUnwrappedPhasePath = parser.get&lt;<a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a>&gt;(8);</div><div class="line"></div><div class="line">Ptr&lt;structured_light::SinusoidalPattern&gt; sinus = structured_light::SinusoidalPattern::create(params);</div><div class="line"><span class="comment">// Storage for patterns</span></div><div class="line">vector&lt;Mat&gt; patterns;</div><div class="line"><span class="comment">//Generate sinusoidal patterns</span></div><div class="line">sinus-&gt;generate(patterns);</div></div><!-- fragment --><p> The number of patterns is always equal to three, no matter the method used to compute the phase map. Those three patterns are projected in a loop which is fine since the system is cyclical.</p>
<p>Once the patterns have been generated, the camera is opened and the patterns are projected, using fullscreen resolution. In this tutorial, a prosilica camera is used to capture gray images. When the first pattern is displayed by the projector, the user can press any key to start the projection sequence.</p>
<div class="fragment"><div class="line">VideoCapture cap(<a class="code" href="../../d4/d15/group__videoio__flags__base.html#gga023786be1ee68a9105bf2e48c700294daea3f59a31f396298b5b3531c23391e49">CAP_PVAPI</a>);</div><div class="line">    <span class="keywordflow">if</span>( !cap.isOpened() )</div><div class="line">    {</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Camera could not be opened&quot;</span> &lt;&lt; endl;</div><div class="line">        <span class="keywordflow">return</span> -1;</div><div class="line">    }</div><div class="line">    cap.set(<a class="code" href="../../dc/dfc/group__videoio__flags__others.html#ggaf63d4c617c61e03ab502b3c836966150af398d565fa74a15b5336cd7d7b4875c1">CAP_PROP_PVAPI_PIXELFORMAT</a>, <a class="code" href="../../dc/dfc/group__videoio__flags__others.html#gga89a5ea2c97ef26165c47e792380b96bca7910aa88e73d326883f0742f760ecae1">CAP_PVAPI_PIXELFORMAT_MONO8</a>);</div><div class="line"></div><div class="line">    <a class="code" href="../../d7/dfc/group__highgui.html#ga5afdf8410934fd099df85c75b2e0888b">namedWindow</a>(<span class="stringliteral">&quot;pattern&quot;</span>, <a class="code" href="../../d0/d90/group__highgui__window__flags.html#ggabf7d2c5625bc59ac130287f925557ac3a29e45c5af696f73ce5e153601e5ca0f1">WINDOW_NORMAL</a>);</div><div class="line">    <a class="code" href="../../d7/dfc/group__highgui.html#ga66e4a6db4d4e06148bcdfe0d70a5df27">setWindowProperty</a>(<span class="stringliteral">&quot;pattern&quot;</span>, <a class="code" href="../../d0/d90/group__highgui__window__flags.html#ggaeedf4023e777f896ba6b9ffb156f57b8a3b6a89b0daf2149dab93f9c6ab99fcc8">WND_PROP_FULLSCREEN</a>, <a class="code" href="../../d0/d90/group__highgui__window__flags.html#ggabf7d2c5625bc59ac130287f925557ac3a78bc64121f612562bbb2fa23d316e84e">WINDOW_FULLSCREEN</a>);</div><div class="line">    <a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a>(<span class="stringliteral">&quot;pattern&quot;</span>, patterns[0]);</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;Press any key when ready&quot;</span> &lt;&lt; endl;</div><div class="line">    <a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a>(0);</div></div><!-- fragment --><p>In this tutorial, 30 images are projected so, each of the three patterns is projected ten times. The "while" loop takes care of the projection process. The captured images are stored in a vector of Mat. There is a 30 ms delay between two successive captures. When the projection is done, the user has to press "Enter" to start computing the phase maps.</p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> nbrOfImages = 30;</div><div class="line"><span class="keywordtype">int</span> count = 0;</div><div class="line"></div><div class="line">vector&lt;Mat&gt; img(nbrOfImages);</div><div class="line"><a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a> camSize(-1, -1);</div><div class="line"></div><div class="line"><span class="keywordflow">while</span>( count &lt; nbrOfImages )</div><div class="line">{</div><div class="line">    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i &lt; (int)patterns.size(); ++i )</div><div class="line">    {</div><div class="line">        <a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a>(<span class="stringliteral">&quot;pattern&quot;</span>, patterns[i]);</div><div class="line">        <a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a>(30);</div><div class="line">        cap &gt;&gt; img[count];</div><div class="line">        count += 1;</div><div class="line">    }</div><div class="line">}</div><div class="line"></div><div class="line">cout &lt;&lt; <span class="stringliteral">&quot;press enter when ready&quot;</span> &lt;&lt; endl;</div><div class="line"><span class="keywordtype">bool</span> loop = <span class="keyword">true</span>;</div><div class="line"><span class="keywordflow">while</span> ( loop )</div><div class="line">{</div><div class="line">    <span class="keywordtype">char</span> c = <a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a>(0);</div><div class="line">    <span class="keywordflow">if</span>( c == 10 )</div><div class="line">    {</div><div class="line">        loop = <span class="keyword">false</span>;</div><div class="line">    }</div><div class="line">}</div></div><!-- fragment --><p> The phase maps are ready to be computed according to the selected method. For FTP, a phase map is computed for each projected pattern, but we need to compute the shadow mask from three successive patterns, as explained in <a class="el" href="../../d0/de3/citelist.html#CITEREF_faps">[49]</a>. Therefore, three patterns are set in a vector called captures. Care is taken to fill this vector with three patterns, especially when we reach the last captures. The unwrapping algorithm needs to know the size of the captured images so, we make sure to give it to the "unwrapPhaseMap" method. The phase maps are converted to 8-bit images in order to save them as png.</p>
<div class="fragment"><div class="line"><span class="keywordflow">switch</span>(params.methodId)</div><div class="line">    {</div><div class="line">        <span class="keywordflow">case</span> <a class="code" href="../../d1/d90/group__structured__light.html#gga8c656fa76189bd6dc1b2a444f680b60aa4652f36554cab9ec596798cdb98aa1c7">structured_light::FTP</a>:</div><div class="line">            <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i = 0; i &lt; nbrOfImages; ++i )</div><div class="line">            {</div><div class="line">                <span class="comment">/*We need three images to compute the shadow mask, as described in the reference paper</span></div><div class="line"><span class="comment">                 * even if the phase map is computed from one pattern only</span></div><div class="line"><span class="comment">                */</span></div><div class="line">                vector&lt;Mat&gt; captures;</div><div class="line">                <span class="keywordflow">if</span>( i == nbrOfImages - 2 )</div><div class="line">                {</div><div class="line">                    captures.push_back(img[i]);</div><div class="line">                    captures.push_back(img[i-1]);</div><div class="line">                    captures.push_back(img[i+1]);</div><div class="line">                }</div><div class="line">                <span class="keywordflow">else</span> <span class="keywordflow">if</span>( i == nbrOfImages - 1 )</div><div class="line">                {</div><div class="line">                    captures.push_back(img[i]);</div><div class="line">                    captures.push_back(img[i-1]);</div><div class="line">                    captures.push_back(img[i-2]);</div><div class="line">                }</div><div class="line">                <span class="keywordflow">else</span></div><div class="line">                {</div><div class="line">                    captures.push_back(img[i]);</div><div class="line">                    captures.push_back(img[i+1]);</div><div class="line">                    captures.push_back(img[i+2]);</div><div class="line">                }</div><div class="line">                sinus-&gt;computePhaseMap(captures, wrappedPhaseMap, shadowMask);</div><div class="line">                <span class="keywordflow">if</span>( camSize.height == -1 )</div><div class="line">                {</div><div class="line">                    camSize.height = img[i].rows;</div><div class="line">                    camSize.width = img[i].cols;</div><div class="line">                }</div><div class="line">                sinus-&gt;unwrapPhaseMap(wrappedPhaseMap, unwrappedPhaseMap, camSize, shadowMask);</div><div class="line">                unwrappedPhaseMap.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#adf88c60c5b4980e05bb556080916978b">convertTo</a>(unwrappedPhaseMap8, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga32b18d904ee2b1731a9416a8eef67d06">CV_8U</a>, 1, 128);</div><div class="line">                wrappedPhaseMap.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#adf88c60c5b4980e05bb556080916978b">convertTo</a>(wrappedPhaseMap8, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga32b18d904ee2b1731a9416a8eef67d06">CV_8U</a>, 255, 128);</div><div class="line"></div><div class="line">                <span class="keywordflow">if</span>( !outputUnwrappedPhasePath.empty() )</div><div class="line">                {</div><div class="line">                    ostringstream name;</div><div class="line">                    name &lt;&lt; i;</div><div class="line">                    <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputUnwrappedPhasePath + <span class="stringliteral">&quot;_FTP_&quot;</span> + name.str() + <span class="stringliteral">&quot;.png&quot;</span>, unwrappedPhaseMap8);</div><div class="line">                }</div><div class="line"></div><div class="line">                <span class="keywordflow">if</span>( !outputWrappedPhasePath.empty() )</div><div class="line">                {</div><div class="line">                    ostringstream name;</div><div class="line">                    name &lt;&lt; i;</div><div class="line">                    <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputWrappedPhasePath + <span class="stringliteral">&quot;_FTP_&quot;</span> + name.str() + <span class="stringliteral">&quot;.png&quot;</span>, wrappedPhaseMap8);</div><div class="line">                }</div><div class="line">            }</div><div class="line">            <span class="keywordflow">break</span>;</div></div><!-- fragment --><p>For PSP and FAPS, three projected images are used to compute a single phase map. These three images are set in "captures", a vector working as a FIFO.Here again, phase maps are converted to 8-bit images in order to save them as png. </p><div class="fragment"><div class="line"><span class="keywordflow">case</span> <a class="code" href="../../d1/d90/group__structured__light.html#gga8c656fa76189bd6dc1b2a444f680b60aa1642d3774551cc6161f49359cc4dd3af">structured_light::PSP</a>:</div><div class="line">        <span class="keywordflow">case</span> <a class="code" href="../../d1/d90/group__structured__light.html#gga8c656fa76189bd6dc1b2a444f680b60aa7f8cbabe23690dec5c877978aa57be7c">structured_light::FAPS</a>:</div><div class="line">            <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i = 0; i &lt; nbrOfImages - 2; ++i )</div><div class="line">            {</div><div class="line">                vector&lt;Mat&gt; captures;</div><div class="line">                captures.push_back(img[i]);</div><div class="line">                captures.push_back(img[i+1]);</div><div class="line">                captures.push_back(img[i+2]);</div><div class="line"></div><div class="line">                sinus-&gt;computePhaseMap(captures, wrappedPhaseMap, shadowMask);</div><div class="line">                <span class="keywordflow">if</span>( camSize.height == -1 )</div><div class="line">                {</div><div class="line">                    camSize.height = img[i].rows;</div><div class="line">                    camSize.width = img[i].cols;</div><div class="line">                }</div><div class="line">                sinus-&gt;unwrapPhaseMap(wrappedPhaseMap, unwrappedPhaseMap, camSize, shadowMask);</div><div class="line">                unwrappedPhaseMap.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#adf88c60c5b4980e05bb556080916978b">convertTo</a>(unwrappedPhaseMap8, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga32b18d904ee2b1731a9416a8eef67d06">CV_8U</a>, 1, 128);</div><div class="line">                wrappedPhaseMap.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#adf88c60c5b4980e05bb556080916978b">convertTo</a>(wrappedPhaseMap8, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga32b18d904ee2b1731a9416a8eef67d06">CV_8U</a>, 255, 128);</div><div class="line"></div><div class="line">                <span class="keywordflow">if</span>( !outputUnwrappedPhasePath.empty() )</div><div class="line">                {</div><div class="line">                    ostringstream name;</div><div class="line">                    name &lt;&lt; i;</div><div class="line">                    <span class="keywordflow">if</span>( params.methodId == <a class="code" href="../../d1/d90/group__structured__light.html#gga8c656fa76189bd6dc1b2a444f680b60aa1642d3774551cc6161f49359cc4dd3af">structured_light::PSP</a> )</div><div class="line">                        <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputUnwrappedPhasePath + <span class="stringliteral">&quot;_PSP_&quot;</span> + name.str() + <span class="stringliteral">&quot;.png&quot;</span>, unwrappedPhaseMap8);</div><div class="line">                    <span class="keywordflow">else</span></div><div class="line">                        <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputUnwrappedPhasePath + <span class="stringliteral">&quot;_FAPS_&quot;</span> + name.str() + <span class="stringliteral">&quot;.png&quot;</span>, unwrappedPhaseMap8);</div><div class="line">                }</div><div class="line"></div><div class="line">                <span class="keywordflow">if</span>( !outputWrappedPhasePath.empty() )</div><div class="line">                {</div><div class="line">                    ostringstream name;</div><div class="line">                    name &lt;&lt; i;</div><div class="line">                    <span class="keywordflow">if</span>( params.methodId == <a class="code" href="../../d1/d90/group__structured__light.html#gga8c656fa76189bd6dc1b2a444f680b60aa1642d3774551cc6161f49359cc4dd3af">structured_light::PSP</a> )</div><div class="line">                        <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputWrappedPhasePath + <span class="stringliteral">&quot;_PSP_&quot;</span> + name.str() + <span class="stringliteral">&quot;.png&quot;</span>, wrappedPhaseMap8);</div><div class="line">                    <span class="keywordflow">else</span></div><div class="line">                        <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(outputWrappedPhasePath + <span class="stringliteral">&quot;_FAPS_&quot;</span> + name.str() + <span class="stringliteral">&quot;.png&quot;</span>, wrappedPhaseMap8);</div><div class="line">                }</div><div class="line">            }</div><div class="line">            <span class="keywordflow">break</span>;</div></div><!-- fragment --> </div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:39 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
